// BEGIN CUT HERE

// END CUT HERE
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <utility>
using namespace std;

#define ALL(v) (v).begin(), (v).end()
#define LET(x,a) typeof(a) x(a)
#define FOR(i,a,n) for(LET(i,a);i!=n;i++)
#define REP(i,n) FOR(i,0,n)
#define sz size()
#define pb push_back
#define LL long long
#define VI vector<int>
#define VII vector< VI >
#define VS vector<string>
#define PRINT(x) REP(i,x.sz) cout<<x[i]<<endl;
#define GI ({int a; cin>>a; a;})
#define COUNT(f,x) ({int _=0;f _+=(x);_;})
#define MIN(f,x) ({LL _=LINF;f _<?=(x);_;})
#define MAX(f,x) (-MIN(f,-(x)))



// BEGIN CUT HERE
#define ARRSIZE(x) (sizeof(x)/sizeof(x[0]))

template<typename T> void print( T a ) {
    cerr << a;
}
static void print( long long a ) {
    cerr << a << "L";
}
static void print( string a ) {
    cerr << '"' << a << '"';
}
template<typename T> void print( vector<T> a ) {
    cerr << "{";
    for ( int i = 0 ; i != a.size() ; i++ ) {
        if ( i != 0 ) cerr << ", ";
        print( a[i] );
    }
    cerr << "}" << endl;
}
template<typename T> void eq( int n, T have, T need ) {
    if ( have == need ) {
        cerr << "Case " << n << " passed." << endl;
    } else {
        cerr << "Case " << n << " failed: expected ";
        print( need );
        cerr << " received ";
        print( have );
        cerr << "." << endl;
    }
}
template<typename T> void eq( int n, vector<T> have, vector<T> need ) {
    if( have.size() != need.size() ) {
        cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements.";
        print( have );
        print( need );
        return;
    }
    for( int i= 0; i < have.size(); i++ ) {
        if( have[i] != need[i] ) {
            cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << ".";
            print( have );
            print( need );
            return;
        }
    }
    cerr << "Case " << n << " passed." << endl;
}
static void eq( int n, string have, string need ) {
    if ( have == need ) {
        cerr << "Case " << n << " passed." << endl;
    } else {
        cerr << "Case " << n << " failed: expected ";
        print( need );
        cerr << " received ";
        print( have );
        cerr << "." << endl;
    }
}
// END CUT HERE
class CDPlayer {
public:
    int isRandom(vector <string> songlist, int n);
};

int dp[2500];

/*
int go(string &s, int pos, int n){
  if(dp[pos] != -1 ) return dp[pos];
  if ( s.sz < n ) return 1;
  int ret = 1 ;
  if( pos >= s.sz - n) { 
    ret = 1;
    bool a[26]; memset(a,0,sizeof(a)); 
    FOR(i,pos,s.sz) { if(a[s[pos]-'a']) ret=0; else a[s[pos]] = true; }
  }
  else{
    bool a[26]; memset(a,0,sizeof(a)); 
    FOR(i,pos,s.sz) { if(a[s[pos]-'a']) ret=0; else a[s[pos]] = true; }
    if(ret) ret = go( s , pos + n , n);
  }
  dp[pos] = ret;
  return ret;
}
*/


int CDPlayer::isRandom(vector <string> s, int n) {
  int res=-1;
  string a = "";
  REP(i,s.sz) a+=s[i];
  memset(dp,-1,sizeof(dp));
  REP(i,n) { int k = go(a,i,n); if(k==1) { res = i; break; } }
  return res;
}
// BEGIN CUT HERE
int main( int argc, char* argv[] ) {
    {
        string songlistARRAY[] = {"BBAC"};
        vector <string> songlist( songlistARRAY, songlistARRAY+ARRSIZE(songlistARRAY) );
        CDPlayer theObject;
        eq(0, theObject.isRandom(songlist, 3),1);
    }
    {
        string songlistARRAY[] = {"BACAB",
            "BCA"};
        vector <string> songlist( songlistARRAY, songlistARRAY+ARRSIZE(songlistARRAY) );
        CDPlayer theObject;
        eq(1, theObject.isRandom(songlist, 3),2);
    }
    {
        string songlistARRAY[] = {"AAACBACBACBACBACBACBACB"};
        vector <string> songlist( songlistARRAY, songlistARRAY+ARRSIZE(songlistARRAY) );
        CDPlayer theObject;
        eq(2, theObject.isRandom(songlist, 3),-1);
    }
    {
        string songlistARRAY[] = {"ABCDEABDECBAECDEDACB"};
        vector <string> songlist( songlistARRAY, songlistARRAY+ARRSIZE(songlistARRAY) );
        CDPlayer theObject;
        eq(3, theObject.isRandom(songlist, 5),0);
    }
    {
        string songlistARRAY[] = {"ABCABCABCABCABCABCABC",
            "ABCABCABCABCABCABCABC"};
        vector <string> songlist( songlistARRAY, songlistARRAY+ARRSIZE(songlistARRAY) );
        CDPlayer theObject;
        eq(4, theObject.isRandom(songlist, 22),-1);
    }
    {
        string songlistARRAY[] = {"AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA",
            "AAAAAAAAAAAAAAAA"};
        vector <string> songlist( songlistARRAY, songlistARRAY+ARRSIZE(songlistARRAY) );
        CDPlayer theObject;
        eq(5, theObject.isRandom(songlist, 1),0);
    }
    {
        string songlistARRAY[] = {"ADEF"};
        vector <string> songlist( songlistARRAY, songlistARRAY+ARRSIZE(songlistARRAY) );
        CDPlayer theObject;
        eq(6, theObject.isRandom(songlist, 12),0);
    }
}
// END CUT HERE
